package com.pc.ssm.tools;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2017-11-22 21:28
 * @Description:
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         ------------------------  
 * 1.0      2017/11/22     dst                               
 *******************************************************************************************
 */
public class GeneratorExecution {
    public static void generator(){

        List<String> warnings=new ArrayList<String>();
        try {
//      导入配置表mybatis-generator.xml
            ClassLoader classloader = Thread.currentThread().getContextClassLoader();
            InputStream is = classloader.getResourceAsStream("mybatis-generator.xml");
            //File configFile=new File("resources/mybatis-generator.xml");

//      解析
            ConfigurationParser cp=new ConfigurationParser(warnings);
            //Configuration config=cp.parseConfiguration(configFile);
            Configuration config=cp.parseConfiguration(is);
//      是否覆盖
            DefaultShellCallback dsc=new DefaultShellCallback(true);
            MyBatisGenerator mg=new MyBatisGenerator(config, dsc, warnings);
            mg.generate(null);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        GeneratorExecution.generator();
        System.out.println("done!");
    }

}
